package top.xiaoqy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.xiaoqy.entity.Gpspoint;
import top.xiaoqy.entity.GpspointParam;
import top.xiaoqy.service.IGpspointService;
import top.xiaoqy.util.Result;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小清远
 * @since 2023-12-28
 */
@RestController
@RequestMapping("/gpspoint")
public class GpspointController {
    @Autowired
    private IGpspointService gpspointService;

    @PostMapping("/save")
    public Result save(@RequestBody Gpspoint gpspoint){
        boolean save = gpspointService.save(gpspoint);
        if (save) {
            System.out.println("保存成功");
            return Result.success();
        }
        return Result.error(500,"添加失败");
    }

    @PutMapping
    //缺少id
    public Result edit(@RequestBody Gpspoint gpspoint){
        boolean update = gpspointService.updateById(gpspoint);
        if (update) {
            System.out.println("编辑成功");
            return Result.success();
        }
        return Result.error(500,"编辑失败");
    }

    @GetMapping("/list")
    public Result getList(GpspointParam param){
        IPage<Gpspoint> page = gpspointService.getList(param);
        return Result.success(page);
    }

}
